Linux
linux= dig * use dig command to find the domain ip dig preview.cn.mobile.reuters.com ;; ANSWER SECTION: preview.cn.mobile.reuters.com. 30 IN A 167.206.188.34 printenv *print all or part of environment >printenv >sudo printenv which * locate a program file in the user's path Rens-MacBook-Pro:~ renyufei$ which node /usr/local/bin/node yum error: Metadata file does not match checksum * https://plone.lucidsolutions.co.nz/linux/rpm/yum-metadata-file-does-not-match-checksum * https://github.com/pagespeed/mod_pagespeed/issues/277 #add "http_caching=packages" to /etc/yum.conf (the default is "http_caching=all") #http_caching = { all, none, packages } >sudo yum clean metadata reference doc *http://linux.vbird.org/ *认识学习Bash - http://linux.vbird.org/linux_basic/0320bash.php command curl * Transfer a url # -d, --data # (HTTP) Sends the specified data in a POST request to the HTTP server curl -d 'hi, the content' http://localhost:3003 * curl get method curl http://localhost:3003 * curl -# -D - -o /dev/null -H "User-Agent:iphone" "http://www.reuters.com/article/2014/03/26/idUSnMKW40mwTa+1c2+MKW20140326" # -D - , dump header to standard output # -# , progress bar # -o, --output , Write output to instead of stdout. lokvins-MacBook-Pro:yufei lokvin$ curl -# -D - -o /dev/null -H "User-Agent:iphone" "http://www.reuters.com" HTTP/1.1 302 Moved Temporarily Server: AkamaiGHost Content-Length: 0 Location: http://mobile.reuters.com/do/urlRedirect?URL=http%3A%2F%2Fwww.reuters.com/ Date: Wed, 02 Jul 2014 14:26:32 GMT Connection: keep-alive Vary: User-Agent * curl with multi Header curl -H "Content-Type: application/json" -H "X-TR-Signature: .." -d "hi, this is test" "http://somedomain.com/push" * curl use PUT method curl -H "Content-Type: application/json" -H "X-TR-Timestamp: " -X PUT -d "apple" "http://somedomain.com/registration" * curl get response time time curl http://www.sina.com.cn > /dev/null 2>&1 wget * non-interactive network downloader, supports http, https, ftp # -O file, if - used as file, documents will be printed to standard output wget -O- "http://172.16.3.10/ric?symbol=GOOG.O" # wget use proxy wget -O- -e use_proxy=yes -e http_proxy=10.90.108.136:23375 http://widerimage.reuters.com/utils/getdata-rts0001 wget with response time time wget http://www.aip.im -q --output-document=/dev/null tee * tee - read from standard input and write to standard output and files less * -N "show line number" * -n "hide line number" * :GG "to last line" * :1G "to first line" * :100G "to no. 100 line" * /searchString "search string" * n "find next" * N "find reverse netxt" ctrl+shift+c , ctrl+shift+v * in shell terminal copy= ctrl+shift+c, paste=ctrl+shift+v disable selinux Disabled SELinux first sudo vi /etc/selinux/config SELINUX=disabled reboot the system please. stop firewalld * https://fedoraproject.org/wiki/FirewallD - docs about firewall # stop firewall sudo systemctl stop firewalld.service check disk usage * check disk usage #df - report file system disk space usage # -h, human readable # -T, print file system type [iphone@bjsit1iphonedev01 ~]$ df -h Filesystem Size Used Avail Use% Mounted on /dev/sda2 107G 17G 85G 17% / tmpfs 974M 4.7M 969M 1% /dev/shm [yufei@localhost ~]$ df -Th Filesystem Type Size Used Avail Use% Mounted on devtmpfs devtmpfs 1.9G 0 1.9G 0% /dev tmpfs tmpfs 1.9G 1.4M 1.9G 1% /dev/shm tmpfs tmpfs 1.9G 20M 1.9G 2% /run * check folder usage # du - estimate file space usage [iphone@bjsit1iphonedev01 ~]$ du -sh * 192K Desktop 40K Documents 810M Downloads 57M jmeter-2.3.4 12K memcached 4.0K Music #current folder diskusage [yufei@localhost ~]$ du -sh 1.8G . lsof //Check specify process open files count shell>sudo /usr/sbin/lsof -p 16508 |wc -l //查找监听 3306 port 的 process shell>lsof -i:3306 ssh with config file *http://nerderati.com/2011/03/17/simplify-your-life-with-an-ssh-config-file/ ssh no password login * enter the ~/.ssh directory [iphone@bjsit1iphonedev01 .ssh]$ ll total 24 -rw------- 1 iphone iphone 406 Jun 29 2010 authorized_keys -rw------- 1 iphone iphone 1679 Jun 29 2010 id_rsa -rw-r--r-- 1 iphone iphone 406 Jun 29 2010 id_rsa.pub -rw-r--r-- 1 iphone iphone 11773 Dec 14 17:00 known_hosts * id_rsa and id_rsa.pub were create by command ssh-keygen -t rsa. id_rsa.pub is your public key, put it's content to the remote machine ~/.ssh/authorized_keys then you can ssh without password. [iphone@bjsit1iphonedev01 .ssh]$ssh-keygen -t rsa -C "your_email@example.com" * know_hosts is the machine list, you ssh connect from. * http://hi.baidu.com/zengzhaonong/blog/item/1b444eda858bc3dab6fd48a6.html - a doc from baidu * https://help.github.com/articles/generating-ssh-keys check system info uname *uname - print system information shell>uname -a [iphone@bjsit1iphonedev01 ~]$ uname -a Linux bjsit1iphonedev01 2.6.33.3-85.fc13.i686.PAE #1 SMP Thu May 6 18:27:11 UTC 2010 i686 i686 i386 GNU/Linux check linux release version shell>cat /etc/redhat-release [iphone@bjsit1iphonedev01 ~]$ cat /etc/redhat-release Fedora release 13 (Goddard) # show first line of /etc/issue file [yufei@localhost ~]$ head -n 1 /etc/issue Fedora release 18 (Spherical Cow) check cup info shell>cat /proc/cpuinfo check memory info shell>cat /proc/meminfo shell>grep MemTotal /proc/meminfo free *free - Display amount of free and used memory in the system [yufei@localhost ~]$ free -h total used free shared buffers cached Mem: 3.7G 3.5G 228M 0B 239M 1.6G -/+ buffers/cache: 1.7G 2.0G Swap: 3.7G 75M 3.6G top * top - display Linux processes uptime * uptime - Tell how long the system has been running. [yufei@localhost ~]$ uptime 13:22:39 up 12 days, 3:08, 6 users, load average: 0.24, 0.16, 0.14 netstat *netstat - Print network connections, routing tables, interface statistics, masquerade connections, and multicast memberships ** http://www.binarytides.com/linux-netstat-command-examples/ (zh translate http://linux.cn/forum.php?mod=viewthread&tid=12158) * '''sudo netstat -lptn''' --- List listening tcp process and port # -l : listen process , -p: process, -t: TCP, -n: not use name resolved $ sudo netstat -lptn Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:8000 0.0.0.0:* LISTEN 6283/java tcp 0 0 0.0.0.0:24800 0.0.0.0:* LISTEN 2483/synergys tcp 0 0 0.0.0.0:23306 0.0.0.0:* LISTEN 2094/mysqld tcp 0 0 0.0.0.0:11211 0.0.0.0:* LISTEN 2164/memcached tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 2218/rpcbind * find which process listen port 80 --- '''sudo netstat -lptn | grep 80''' [yufei@us ~]$ sudo netstat -lptn | grep 80 tcp6 0 0 :::80 :::* LISTEN 2378/httpd * '''sudo netstat -lpte''' --- List listening tcp process and user [yufei@us ~]$ sudo netstat -lpte Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State User Inode PID/Program name tcp 0 0 *:irdmi *:* LISTEN root 1407395 6283/java tcp 0 0 *:24800 *:* LISTEN root 25483 2483/synergys tcp 0 0 *:23306 *:* LISTEN mysql 24100 2094/mysqld tcp 0 0 *:memcache *:* LISTEN nobody 24636 2164/memcached tcp 0 0 *:sunrpc *:* LISTEN root 25644 2218/rpcbind tcp 0 0 *:ssh *:* LISTEN root 25715 2212/sshd tcp 0 0 localhost:ipp *:* LISTEN root 22127 1573/cupsd tcp 0 0 localhost:smtp *:* LISTEN root 25723 2223/sendmail: acce route *route - show / manipulate the IP routing table w * w - Show who is logged on and what they are doing. [yufei@localhost ~]$ w 13:30:48 up 12 days, 3:16, 6 users, load average: 0.08, 0.11, 0.13 USER TTY LOGIN@ IDLE JCPU PCPU WHAT yufei :0 12Dec13 ?xdm? 3:49m 0.13s gdm-session-worker [pam/gdm-password] yufei pts/0 Thu13 2:20m 2.77s 2.71s ssh distuser@10.90.39.170 last * show listing of last logged in users yufei pts/2 :0 Mon Dec 23 17:03 - 19:03 (02:00) yufei pts/1 :0 Mon Dec 23 15:22 - 19:03 (03:41) evn *env - run a program in a modified environment shell>env show all user name [yufei@localhost ~]$ cut -d: -f1 /etc/passwd root bin ... show all group name [yufei@localhost ~]$ cut -d: -f1 /etc/group root bin ... Chinese input (Fedor 18) # Activity --> System Setting --> Region & Language --> Input Sources --> add "Chinese (Intelligence Pinyin)" --> in shortcut setting, add shortcut for "Switch to next source" eg. ctrl+space add sudo privilege su root chmod +w /etc/sudoers echo '${username} ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers chmod -w /etc/sudoers exit *check current user sudo privilege info shell>sudo -l change linux hostname vi /etc/sysconfig/network vi /etc/hosts reboot system hostname * hostname - show or set the system's host name [yufei@localhost ~]$ hostname localhost.localdomain # -s , show short hostname [yufei@localhost ~]$ hostname -s localhost telnet tips telent telnet 10.33.133.62 port Connected to produsx-iphoneapp-02.g3.reuters.com (10.33.133.62). Escape character is '^]'. ctrl + ] // 结束http 消息 ^] telnet> quit check dns host -t TXT qa2-iphoneapp-info host -i qa2-admindb-vip VNC settings set vnc server with display rate, edit file /etc/sysconfig/vncservers shell>sudo vi /etc/sysconfig/vncservers VNCSERVERS="1:iphone" VNCSERVERARGS[1]="-geometry 1280x800" fc18 install VNC shell>su shell>yum -y install tigervnc-server # change the user you want to vnc shell>su john shell>vncserver :1 -geometry 1600x900 -depth 24 * create shell for start vnc under ~/bin/start-vnc.sh , content like below: vncserver :1 -geometry 1600x900 -depth 24 [yufei@us bin]$ vncserver help vncserver -list vncserver -kill vncserver -kill :1 * vnc viewer change screen size, ctrl + alt + shift + f check your shell shell> echo $SHELL /bin/bash cron tab *http://www.adminschoice.com/crontab-quick-reference - crontab ref cron file in folder, use user name as file name /var/spool/cron [distuser@qa2-admin-01 ~]$ sudo ls -l /var/spool/cron/ total 16 -rw------- 1 root root 477 Sep 12 20:53 lisa -rw------- 1 root root 217 Sep 24 08:45 rmg -rw------- 1 root root 300 Oct 5 10:08 root -rw------- 1 runnerman root 1134 Jan 8 2014 runnerman [distuser@qa2-admin-01 ~]$ sudo cat /var/spool/cron/root 00 23 * * * /root/scripts/cmsbackfill.sh 0 * * * * cat /dev/null > /usr/local/mysql/data/mysqld/mysqld-slow.log 0 * * * * cat /dev/null > /usr/local/mysql/data/mysqld2/mysqld-slow.log 00 17 * * * mysql -u root -pr00t --port=23308 --socket=/rt/db/tmp/mysqld.sock3 -e 'purge binary logs before now();' crontab -u user -l [distuser@qa2-admin-01 ~]$ sudo crontab -u root -l 00 23 * * * /root/scripts/cmsbackfill.sh ##remove cron job crontab -r ctrl + r ## search history command shell> ctrl + r killall kill a batch of process with same name pattern. [distuser@qa2-iphoneweb-01 ~]$ sudo killall cronInvoker.sh * kill all process for specify user >sudo killall -u runnerman file privilege -rwxrwxrwx user/group/others r:4, w:2, x:1 r + w + x = 7 r + w = 6 r + x = 5 * 修改用户所属 group , chgrp shell>chgrp -R users dirnmae/filename * 修改文件拥有者 chown shell> chown -R 用户 dirname/filename shell> chown -R 用户:组 install.log * 修改文件的权限 chmod //-R 是递归 recursive 数字权限法 shell> chmod -R 777 dirname/filename u,g,o,a 权限法， + (加入)， - (减去)， = (设置) shell> chmod u=rwx,go=rx filename shell> chmod a+w filename shell> chmod a-w filename pwd shell> pwd //显示当前目录 shell> pwd -P //显示当前目录，将 soft link 转为真实目录 mkdir shell> mkdir -m 711 dir1 //建立目录，并指定目录的 r,w,x 权限 shell> mkdir -p dir2/child //建立多级目录 cat //cat 将文件输出到标准输出 shell>cat .bash_profile //将 file1 , file2 的内容合并放入 file3 shell> cat file1 file2 > file3 // 将 foo.txt 内容追加到 love.txt 之后 shell> cat foo.txt >> love.txt ls * ls 列出的文件类型 [ d ]是目录 [ - ]是文件 [ l ]表示link file(软链接) [ b ]表示随机读取的存储设备； [ c ]表示顺序读取设备，如键盘、鼠标 /etc/bashrc * /etc/bashrc 是全局的环境配置文件 一般引用顺序 /etc/basrc --> ~/.basrc --> ~/.bash_profile set path variable shell >vi /home/${user}/.bash_profile add to path variable following entries: :/usr/bin:/bin:/sbin:/usr/sbin:/usr/local/bin: install jdk download a new version jdk ,such as jdk-6u16-linux-i586.bin shell >sudo chmod a+x jdk-6u16-linux-i586.bin shell >./jdk-6u16-linux-i586.bin shell >sudo mkdir /usr/java shell >sudo mv jdk1.6.0_16 /usr/java/jdk1.6.0_16 add /usr/java/jdk1.6.0_16/bin to path shell >vi ~/.bash_profile create soft link for java and javac shell >sudo ln -s /usr/java/jdk1.6.0_16/bin/java /usr/bin/java shell >sudo ln -s /usr/java/jdk1.6.0_16/bin/javac /usr/bin/javac shell >java -version install maven download apache-maven-2.2.1-bin.zip shell >unzip apache-maven-2.2.1-bin.zip shell >mv apache-maven-2.2.1 ~/maven-2.2.1 # add maven/bin to .bash_profile # export JAVA_HOME parameter shell >mvn -version Apache Maven 2.2.1 (r801777; 2009-08-07 03:16:01+0800) Java version: 1.6.0_16 Java home: /usr/java/jdk1.6.0_16/jre Default locale: en_US, platform encoding: UTF-8 OS name: "linux" version: "2.6.27.5-117.fc10.i686" arch: "i386" Family: "unix" install ant download apache-ant-1.7.1-bin.tar.gz shell >tar -zxvf apache-ant-1.7.1-bin.tar.gz shell >mv apache-ant-1.7.1 ~/ant-1.7.1 ＃add ant/bin to .bash_profile shell >ant -version Apache Ant version 1.7.1 compiled on June 27 2008 more more 分页显示 shell>ls -al | more shell> cat foo.txt | more /etc/shells 系统可用的 shell 在 /etc/shells 文件中记录 localhost:bin lokvin$ cat /etc/shells # List of acceptable shells for chpass(1). # Ftpd will not allow users to connect who are not using # one of these shells. /bin/bash /bin/csh /bin/ksh /bin/sh /bin/tcsh /bin/zsh .bash_history 你所输入过的 命令，记录在文件 ~/.bash_history 中 alias alias 设置别名，可以设置在文件 ~/.bash_profile 中 直接输入 alias ，查询当前可用别名 alias ll='ls -al' * some time you need add shell file under /etc/profile.d , such as: yufei_alias.sh [yufei@localhost profile.d]$ cat /etc/profile.d/yufei_alias.sh alias jumpfoo='ssh jump@10.xx' ps aux | grep #查找类似名称的 process #bsd style shell> ps aux | grep firefox #unix/linux stype shell> ps -ef | grep firefox * '''ps aux --sort=-pcpu,+pmem''' , sort by cpu , memory, - is desc order, + is asc order ## find memory consumed top 5 process ps aux --sort=-pmem | head -6 common install from source *一般的从源码安装步骤 #--with-prefix 指定安装位置 shell> ./configure --with-prefix=/usr/local/dirname shell> make shell> make install whereis * find a command path ldev:mex-webdistribution-common renyufei$ whereis mvn /usr/bin/mvn check dns [hudson@HPGQA2AGENCY01 ~]$ cat /etc/resolv.conf search g3agency.reuters.com #nameserver 10.90.106.52 nameserver 10.90.22.14 nameserver 10.90.26.14 [hudson@HPGQA2AGENCY01 ~]$ host gitlab.media.reuters.com ;; connection timed out; no servers could be reached [hudson@HPGQA2AGENCY01 ~]$ nslookup gitlab.media.reuters.com Server: 10.90.26.14 Address: 10.90.26.14#53 Non-authoritative answer: Name: gitlab.media.reuters.com Address: 10.90.106.3 short cut key # ctrl + a , move cursor to begin of line # ctrl + e , move cursor to end of line # ctrl + u , cut from begin to the cursor # ctrl + k , cut from curson to the end # ctrl + w , cut 1 word before cursor # alt + d, cut 1 word after cursor # ctrl + y , paste previous cut # ctrl + f (-> arrow) , move cursor right 1 char # ctrl + b (<- arrow), move cursor left 1 char # ctrl + -> arrow (<- arrow) , move cursor right (left) 1 word # ctrl + d (delete key), delete cursor right 1 char # alt + u , change to upper case (cursor right 1 word) # alt + i, change to lower case (cursor right 1 word) # ctrl + shift + t , open new terminal tab # ctrl + shift + w , close current terminal tab # ctrl + shift + n , open new terminal window # ctrl + shift + q , close terminal window # ctrl + shift + c, copy in terminal # ctrl + shift + v, paste in terminal # f11 , full screen terminal # ctrl + , zoom in terminal # ctrl - , zoom out terminal # ctrl + 0 (zero), normal size terminal # ctrl + shift + f , find in terminal # ctrl + shift + h , find next # ctrl + shift + g , find previous # ctrl + page down , next tab # ctrl + page up, prevous tab # ctrl + shift + page down, move tab to right # ctrl + shift + page up, move tab to left BASH_REMATCH why regexp doesn't work http://stackoverflow.com/questions/13150411/why-bash-rematch-doesnt-work-on-my-computer *In your bash REGEX, you should remove quotes. That's why that doesn't work. yum proxy shell> sudo vi /etc/yum.conf #add correct proxy for your env proxy=http://10.90.7.56:3128/ yum repo dir /etc/yum.repos.d yum clean cache * clean yum cache sudo yum clean all yum on caching * edit file /etc/yum.conf, add follow line for no cache http_caching=none yum list * yum list sudo yum list memcached_145_config add icon to fe18 gnome-desktop-item-edit /usr/share/applications/ --create-new fe18 show desktop icons gsettings set org.gnome.desktop.background show-desktop-icons true install by yum shell> sudo yum install memcached check user, group exist shell>cat /etc/group | grep xxx shell>id groupname shell>cat /etc/passwd | grep xxx shell>id username rsync *use rsync copy file with exlude rsync -rv --exclude=.git demo demo_bkp grep * grep content from file name [distuser@qa6-ftp-01 apache22]$ grep -H 23381 conf/**/**/** conf/conf.d/proxy/rcom-vhosts.conf: set github proxy ssh proxy Add below two lines to your ~/.ssh/config HOST github.com ProxyCommand ssh distuser@10.90.39.170 "nc %h %p" config file properties should be: [yufei@localhost project]$ ls -al ~/.ssh/config -r--r--r-- 1 root root 69 Oct 30 11:31 /home/yufei/.ssh/config For http,https protocol (eg: https://github.com/mochi/mochiweb.git) Run below command to add corresponding configs to ~/.gitconfig. $ git config --global http.proxy http://10.90.7.56:3128/ set git properties [yufei@localhost project]$ git config --global user.name "Yufei Ren" [yufei@localhost project]$ git config --global user.email yufei.ren@thomsonreuters.com check git properties git config --list install git on centos 5.5 http://www.konordo.com/blog/installing-git-centos-55-yum shell set variable # no empty before/after =, # var name should character and number, can NOT start with number # 可以使用 "", '' 将空格内容组合起来。 "$var" is variable value, '$var' 是字面量 # `command`, 可以执行 command # export var, 使成为环境变量，可以在 child process 中使用 var # unset var, 取消变量设置 # 一般环境变量upper case, 自定义变量 lower case shell>myname=yufei shell>echo $myname shell>echo ${myname} # 显示环境变量 env shell>env # set 显示其他所有环境变量 shell>set # 重要的几个 PS1, 提示符设置 PS1='\h:\W \u\$ ' # '''$''' 当前shell pid ldev:example renyufei$ echo $$ 25224 # '''?'''上条命令的 return code shell>echo $? shell>0 ; && || * run multi shell command in one line use ';' separate shell>sync; sync; shutdonw -h now * =env setup= *[[linux env setup]] - env setup *[[rcom setup]] - rcom setup *[[linux setup cory]] - linux setup cory *[[install fedora21]] - install fedora21 *[[install ubuntu 14.04]] - install ubuntu 14.04 =linux performance tools